﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using kdRPG;

namespace kdRPG.Map
{
    class Tile
    {
        private Texture2D texture = null;
        private Texture2D texture2 = null;
        private Player player;
        private Vector2 position;
        private bool solid, isColliding = false;
        private Rectangle collisionRect;
        public bool isHit = false;

        public Tile(Texture2D texture, Texture2D texture2, ref Player player, float x, float y, bool solid)
        {
            this.texture = texture;
            this.texture2 = texture2;
            this.player = player;
            this.position = new Vector2(x, y);
            this.collisionRect = new Rectangle((int)x, (int)y, texture.Width, texture.Height);
            this.solid = solid;
        }

        public void update(GameTime gameTime)
        {
            checkCollision();
        }
        public void draw(SpriteBatch spriteBatch)
        {
            Texture2D temp;
            if (isHit)
                temp = texture2;
            else
                temp = texture;
            
            if (isColliding)
                spriteBatch.Draw(temp, collisionRect, Color.Red);
            else
                spriteBatch.Draw(temp, collisionRect, Color.White);
        }

        public void checkCollision()
        {
            if (player.CollisionRectangle.Intersects(collisionRect))
            {
                isColliding = true;
                player.isNowColliding(this);
            }
            else
                isColliding = false;
        }

        public bool isSolid()
        {
            return solid;
        }

        
        public Rectangle CollisionRectangle
        {
            get { return collisionRect; }
        }

        public float Height
        {
            get { return texture.Height; }
        }

        public float Width
        {
            get { return texture.Width; }
        }
    }
}
